package com.tonann.app.conf;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class ConvertHandler {

    public static <T> List<List<T>> splitList(List<T> list, final int size) {
        if (size <= 0) {
            throw new IllegalArgumentException("Size must be positive");
        }
        return IntStream.range(0, (list.size() + size - 1) / size)
                .mapToObj(i -> list.subList(i * size, Math.min(list.size(), (i + 1) * size)))
                .collect(Collectors.toList());
    }
}
